﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using Business;
using Database;

namespace DT5_Anh09110006_Hung09110044_Vu09110157.QuanLy
{
    public partial class QuanLyLopHoc : System.Web.UI.Page
    {
        Business.QuanLyLopHoc qllophoc = new Business.QuanLyLopHoc();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loaddulieu();
            }

        }
        private void loaddulieu()
        {
            grvQlLopHoc.DataSource = qllophoc.LayDanhSachLopHoc();
            grvQlLopHoc.DataBind();
        }
        protected void grvQlLopHoc_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grvQlLopHoc.PageIndex = e.NewPageIndex;
            loaddulieu();

        }

        protected void grvQlLopHoc_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("ChiTiet"))
            {
                Session["MaLopHoc"] = e.CommandArgument;
                Response.Redirect("ChiTietLopHoc.aspx");
            }
            if (e.CommandName.Equals("Sua"))
            {
                Session["MaLopHoc"] = e.CommandArgument;
                Response.Redirect("SuaLopHoc.aspx");
            }
            if (e.CommandName.Equals("Xoa"))
            {
                if (qllophoc.XoaLopHoc(e.CommandArgument.ToString()))
                {

                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectMe", "alert('Không thể xóa lớp học này');", true);
                }
                loaddulieu();
            }
        }

        protected void btnThemLH_Click(object sender, EventArgs e)
        {
            Response.Redirect("ThemLopHoc.aspx");
        }

     
    }
}